﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using System.Web;
using System.Web.Mvc;
using Sharp.DataTransferObject;
using Sharp.Infrastructure.WebApiClient;
using Sharp.Portal.Mvc;
using Sharp.Portal.Mvc.Models;
using Sharp.ServiceContracts;
using Sharp.WebBooter.Areas.Demo.Models;
using Sharp.WebBooter.Areas.Platform.Controllers;


namespace Sharp.WebBooter.Areas.Demo.Controllers
{
    [Authorize]
    [AutomaticTemplate]
    public class DefaultController : SharpController
    {
        /// <summary>
        /// 控件展示
        /// </summary>
        /// <returns></returns>
        public async Task<ActionResult> Control()
        {
            var vm = new ControlModel()
            {
                UI = {
                    OpenWith = Portal.OpenWith.Tile2Column,
                    //IsReadOnlyForm =true
                }
            };
            vm.Phone = "13849958585";
            vm.DateA = DateTime.Parse("2017-01-01");
            vm.Email = "test@abc.com";
            vm.MultilineText = "a\r\n多行文本\r\n2\r\n";
            vm.Currency = "1.34";
            vm.ImageUrl = "//www.baidu.com/img/bd_logo1.png";
            vm.ImageUpload = "//www.baidu.com/img/bd_logo.png";
            vm.Html = "<br />1<br />1<br />1";
            vm.GenderCode = "1";
            vm.BoolInput = true;
            vm.UserName = "SelectBox";
            vm.UserId = "SelectBoxValue";

            IEnumerable<OrgDTO> allOrgs;
            using (var proxy = new WebApiClientServiceProxy<IEnterpriseService>())
            {
                allOrgs = await proxy.Channel.GetOrgs();
            }
            vm.OrgIdDataSource = new zTreeNode();
            OrgController.Build(allOrgs, vm.OrgIdDataSource, null);

            vm.DropDownListFieldDataSource = allOrgs.ToList();

            //return View("ValidationTesting", vm);
            return View(vm);
        }
        [ValidateInput(false)]
        public ActionResult Save(ControlModel model)
        {
            return View();
        }

        public ActionResult RenderWindow(string selectTextControl)
        {
            ViewBag.SelectTextControl = selectTextControl;
            return View("Window");
        }
    }
}